<?php
namespace Admin\Controller;

// 本类由系统自动生成，仅供测试用途
class SuggestController extends PublicController {

    function _initialize() {
        parent::_initialize ();
    }

    public function index() {
        if (! session("wadmin")) {
            $this->error ( "登录失败", U ( "Admin/Login/index" ) );
        }else{
            $store_id = session("wadmin");
            if ($store_id['store_id']==0) {
                $map = '';
            } else {
                $map['p.store_id'] = $store_id['store_id'];
            }

            $count = M("suggest")->alias("p")->where($map)->count (); // 查询满足要求的总记录数
            $Page = new \Think\Page($count, 12);// 实例化分页类 传入总记录数和每页显示的记录数
            $Page->setConfig('theme', "<ul class='pagination no-margin pull-right'></li><li>%FIRST%</li><li>%UP_PAGE%</li><li>%LINK_PAGE%</li><li>%DOWN_PAGE%</li><li>%END%</li><li><a> %HEADER%  %NOW_PAGE%/%TOTAL_PAGE% 页</a></ul>");//(对thinkphp自带分页的格式进行自定义)
            $show = $Page->show (); // 分页显示输出
            $result = M("suggest")->alias("p")->join("meal_store as s on p.store_id=s.store_id")->field("p.*,s.store_name")->where($map)->limit ( $Page->firstRow . ',' . $Page->listRows )->order("p.id desc")->select ();

            //店铺信息（所有的店铺）
            foreach ($result as &$v){
                $v['picList'] = explode(',', ($v['pic']));
            }

            $this->assign ( "result", $result );
            $this->assign ( "page", $show ); // 赋值分页输出
            $this->display ();
        }
    }


}